package 力扣;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class leetcode454 {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        HashMap<Integer,Integer> map1=new HashMap<>();
        HashMap<Integer,Integer> map2=new HashMap<>();
        for (int i = 0; i < nums1.length; i++) {
            for (int i1 = 0; i1 < nums2.length; i1++) {
                if(!map1.containsKey(nums1[i]+nums2[i1]))
                map1.put(nums1[i]+nums2[i1],1);
                else map1.put(nums1[i]+nums2[i1],map1.get(nums1[i]+nums2[i1])+1);
            }
        }
        for (int i = 0; i < nums3.length; i++) {
            for (int i1 = 0; i1 < nums4.length; i1++) {
                if(!map2.containsKey(nums3[i]+nums4[i1]))
                    map2.put(nums3[i]+nums4[i1],1);
                else map2.put(nums3[i]+nums4[i1],map2.get(nums3[i]+nums4[i1])+1);
            }
        }
        int count=0;
        for (Integer integer : map1.keySet()) {
            if(map2.containsKey(0-integer)) count=count+map2.get(integer)*map1.get(integer);
        }
        return count;
    }
}
